<#--
    模板名称：CREATE TABLE
    语句说明：https://doris.apache.org/zh-CN/docs/3.0/sql-manual/sql-statements/Data-Definition-Statements/Create/CREATE-TABLE
    输入参数：
        dw      MetaWarehouse
        table   MetaTable
-->

<#assign keys_str = "">

CREATE TABLE IF NOT EXISTS `${dw.getDwName()}`.`${table.getTableName()}`
(<#rt>
    <#-- column_definition_list -->
    <#list table.getColumns() as col>
        <#include "*/ddl-column.ftl"><#sep>,</#sep><#rt>
        <#if col.getIsPk() == 1>
            <#assign keys_str += ",">
            <#assign keys_str += "`" + col.getColumnName() + "`">
        </#if>
    </#list>
)
<#-- keys_type -->
<#if keys_str?length != 0>
    <#if table.getTableType() == 'DUPLICATE'>
    DUPLICATE KEY<#t>
    <#elseif table.getTableType() == 'UNIQUE'>
    UNIQUE KEY<#t>
    <#elseif table.getTableType() == 'AGGREGATE'>
    AGGREGATE KEY<#t>
    </#if>
    (${keys_str?remove_beginning(",")})<#t>
</#if>
<#-- table_comment -->
<#if table.getComment()??>
COMMENT "${table.getComment()}"
</#if>
;<#t>